package com.hqyj.springboot.springboot_multiple_order.handler;

import com.hqyj.springboot.springboot_multiple_order.mapper.OrderMapper;
import com.hqyj.springboot.springboot_multiple_order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.Order;
import pojo.RestfulEntity;

@Controller
public class OrderHandler {
    @Autowired
    private OrderService orderService;

    @PostMapping(value = "app")
    public @ResponseBody RestfulEntity add(@RequestBody Order order) {
        boolean appendOrder = orderService.appendOrder(order);
        RestfulEntity restfulEntity = new RestfulEntity();
        if (appendOrder){
            restfulEntity.setCode(200);
            restfulEntity.setMessage("success");
        } else {
            restfulEntity.setCode(111);
            restfulEntity.setMessage("失败");
        }
        return restfulEntity;
    }
}
